package com.example.webcrawlercoursedesign;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 数据库管理类
 */

public class MySQLite extends SQLiteOpenHelper {
	private static final int VERSION = 1;
	private static final String SQL_NAME = "NEWS_CACHE";//数据库名称

	//表名称
	public static final String FOOD_NAME = "foodSafety";
	public static final String NETEASE_NAME  = "netEaseCache";
	public static final String HUPU_NAME = "hupuCache";
	public static final String SINA_NAME = "sinaCache";
	public static final String CCTV_NAME = "cctvCache";
	public static final String TENCENT_NAME = "tencentCache";

	//建表语句
	private static final String foodSafety = "create table if not exists foodSafety(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";
	private static final String netEaseCache = "create table if not exists netEaseCache(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";
	private static final String hupuCache = "create table if not exists hupuCache(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";
	private static final String sinaCache = "create table if not exists sinaCache(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";
	private static final String cctvCache = "create table if not exists cctvCache(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";
	private static final String tencentCache = "create table if not exists tencentCache(id integer primary key autoincrement," +
			"url text," +
			"title text," +
			"digest text," +
			"time text," +
			"imageUrl text)";

	//构造方法，若数据库不存在则创建
	MySQLite(Context context) {
		super(context, SQL_NAME, null, VERSION);
	}

	//新建MySQLite对象时调用onCreate方法
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(foodSafety);
		db.execSQL(netEaseCache);
		db.execSQL(hupuCache);
		db.execSQL(sinaCache);
		db.execSQL(cctvCache);
		db.execSQL(tencentCache);
		Log.d("onCreate", netEaseCache);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}
}
